﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Htse.Blue.Models;
using Htse.Blue.Logic.Validation;
using Htse.Blue.Data;
using System.Linq.Dynamic;

namespace Htse.Blue.Logic
{
	public class CategoryService :
		ServiceBase<Category, int, ICategoryRepository>,
		ICategoryService
	{
		public CategoryService(IValidationDictionary<Category> validationDictionary)
			: base(validationDictionary, new CategoryRepository())
		{
		}

		public CategoryService(
			IValidationDictionary<Category> validationDictionary,
			ICategoryRepository repository)
			: base(validationDictionary, repository)
		{
		}

		protected override void ValidateAlways(
			Category entityToValidate,
			IValidationDictionary<Category> validationDictionary)
		{
			if (entityToValidate.Name.Length == 0)
			{
				validationDictionary.AddError(c => c.Name, "Il nome è obbligatorio");
			}
			if (entityToValidate.Description.Length == 0)
			{
				validationDictionary.AddError(c => c.Description, "La descrizione è obbligatoria");
			}
		}
	}
}
